package com.project.utility;

import java.io.File;
import java.util.Date;

import com.project.database.SchemaHelper;
import com.project.database.TableRss;
import com.project.enums.EnumWebsite;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;

public class Global {
	
	public static File getExternalFilesDir(Context context){
		String packageName = context.getPackageName();
		File externalPath = Environment.getExternalStorageDirectory();
		File appFiles = new File(externalPath.getAbsolutePath()
				+ "/Android/data/" + packageName + "/files");
		return appFiles;
	}
	
	public static boolean isNetworkAvailable(Context context) {
	    ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
	    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
	    // if no network is available networkInfo will be null
	    // otherwise check if we are connected
	    if (networkInfo != null && networkInfo.isConnected()) {
	        return true;
	    }
	    return false;
	}
	
	public static void initailizeFeeds(Context context) {
		SharedPreferences sp = context.getSharedPreferences(UserSharedPreferences.SHARED_PREFERENCE_NAME,Context.MODE_PRIVATE);
		boolean isFirst = sp.getBoolean(UserSharedPreferences.IS_FIRST, true);
		if(isFirst){
			SchemaHelper schemaHelper = new SchemaHelper(context);
			Editor editor = sp.edit();
			editor.putBoolean(UserSharedPreferences.IS_FIRST, false);
			editor.commit();
			
			TableRss rssItem1 = new TableRss();
			rssItem1.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem1.setCategory("6 Minute English");
			rssItem1.setDescription("6 Minute English"); 
			rssItem1.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/how2/rss.xml");
			rssItem1.setPubDate(new Date()); 
			
			TableRss rssItem2 = new TableRss();
			rssItem2.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem2.setCategory("Study in the UK (Mandarin)");
			rssItem2.setDescription("Study in the UK (Mandarin)"); 
			rssItem2.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/suk/rss.xml");
			rssItem2.setPubDate(new Date()); 
			
			
			TableRss rssItem3 = new TableRss();
			rssItem3.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem3.setCategory("Playtime (BBC Learning)");
			rssItem3.setDescription("Playtime (BBC Learning)"); 
			rssItem3.setLink("http://downloads.bbc.co.uk/podcasts/radio/playtime/rss.xml");
			rssItem3.setPubDate(new Date()); 
			
			TableRss rssItem4 = new TableRss();
			rssItem4.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem4.setCategory("Listen and Play (BBC Learning)");
			rssItem4.setDescription("Listen and Play (BBC Learning)"); 
			rssItem4.setLink("http://downloads.bbc.co.uk/podcasts/radio/listenplay/rss.xml");
			rssItem4.setPubDate(new Date()); 
			
			TableRss rssItem5 = new TableRss();
			rssItem5.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem5.setCategory("Something To Think About (BBC Learning)");
			rssItem5.setDescription("Something To Think About (BBC Learning)"); 
			rssItem5.setLink("http://downloads.bbc.co.uk/podcasts/radio/stta/rss.xml");
			rssItem5.setPubDate(new Date()); 
			
			TableRss rssItem6 = new TableRss();
			rssItem6.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem6.setCategory("The English We Speak");
			rssItem6.setDescription("The English We Speak"); 
			rssItem6.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/tae/rss.xml");
			rssItem6.setPubDate(new Date()); 
			
			TableRss rssItem7 = new TableRss();
			rssItem7.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem7.setCategory("Forum - A World of Ideas");
			rssItem7.setDescription("Forum - A World of Ideas"); 
			rssItem7.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/forum/rss.xml");
			rssItem7.setPubDate(new Date()); 
			
			TableRss rssItem8 = new TableRss();
			rssItem8.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem8.setCategory("Last Word");
			rssItem8.setDescription("Last Word"); 
			rssItem8.setLink("http://downloads.bbc.co.uk/podcasts/radio4/lastword/rss.xml");
			rssItem8.setPubDate(new Date()); 
			
			TableRss rssItem9 = new TableRss();
			rssItem9.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem9.setCategory("Learning English for China");
			rssItem9.setDescription("Learning English for China"); 
			rssItem9.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/aab/rss.xml");
			rssItem9.setPubDate(new Date()); 
			
			TableRss rssItem10 = new TableRss();
			rssItem10.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem10.setCategory("English At Work");
			rssItem10.setDescription("English At Work"); 
			rssItem10.setLink("http://downloads.bbc.co.uk/podcasts/worldservice/eaw/rss.xml");
			rssItem10.setPubDate(new Date()); 
			
			TableRss rssItem11 = new TableRss();
			rssItem11.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem11.setCategory("Poetry 2012- The Written World");
			rssItem11.setDescription("Poetry 2012- The Written World"); 
			rssItem11.setLink("http://downloads.bbc.co.uk/podcasts/scotland/poetry2012/rss.xml");
			rssItem11.setPubDate(new Date()); 
			
			TableRss rssItem12 = new TableRss();
			rssItem12.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem12.setCategory("My Own Shakespeare");
			rssItem12.setDescription("My Own Shakespeare"); 
			rssItem12.setLink("http://downloads.bbc.co.uk/podcasts/radio4/myshakespeare/rss.xml");
			rssItem12.setPubDate(new Date()); 
			
			TableRss rssItem13 = new TableRss();
			rssItem13.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem13.setCategory("A History of the World in 100 Objects");
			rssItem13.setDescription("A History of the World in 100 Objects"); 
			rssItem13.setLink("http://downloads.bbc.co.uk/podcasts/radio4/ahow/rss.xml");
			rssItem13.setPubDate(new Date()); 
			
			TableRss rssItem14 = new TableRss();
			rssItem14.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem14.setCategory("The Art of Monarchy");
			rssItem14.setDescription("The Art of Monarchy"); 
			rssItem14.setLink("http://downloads.bbc.co.uk/podcasts/radio4/r4monarchy/rss.xml");
			rssItem14.setPubDate(new Date()); 
			
			TableRss rssItem15 = new TableRss();
			rssItem15.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem15.setCategory("Stargazing LIVE Audio Guides 2012");
			rssItem15.setDescription("Stargazing LIVE Audio Guides 2012"); 
			rssItem15.setLink("http://downloads.bbc.co.uk/podcasts/radio/stargazing/rss.xml");
			rssItem15.setPubDate(new Date()); 
			
			TableRss rssItem16 = new TableRss();
			rssItem16.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem16.setCategory("A Brief History of Mathematics");
			rssItem16.setDescription("A Brief History of Mathematics"); 
			rssItem16.setLink("http://downloads.bbc.co.uk/podcasts/radio4/maths/rss.xml");
			rssItem16.setPubDate(new Date()); 
				
			TableRss rssItem17 = new TableRss();
			rssItem17.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem17.setCategory("Time To Move (BBC Learning)");
			rssItem17.setDescription("Time To Move (BBC Learning)"); 
			rssItem17.setLink("http://downloads.bbc.co.uk/podcasts/radio/ttm/rss.xml");
			rssItem17.setPubDate(new Date()); 
			
			TableRss rssItem18 = new TableRss();
			rssItem18.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem18.setCategory("Let's Move (BBC Learning)");
			rssItem18.setDescription("Let's Move (BBC Learning)"); 
			rssItem18.setLink("http://downloads.bbc.co.uk/podcasts/radio/letsmove/rss.xml");
			rssItem18.setPubDate(new Date()); 
			
			TableRss rssItem19 = new TableRss();
			rssItem19.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem19.setCategory("Music Workshop (BBC Learning)");
			rssItem19.setDescription("Music Workshop (BBC Learning)"); 
			rssItem19.setLink("http://downloads.bbc.co.uk/podcasts/radio/musicwkshp/rss.xml");
			rssItem19.setPubDate(new Date()); 
			
			TableRss rssItem20 = new TableRss();
			rssItem20.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem20.setCategory("Together (BBC Learning)");
			rssItem20.setDescription("Together (BBC Learning)"); 
			rssItem20.setLink("http://downloads.bbc.co.uk/podcasts/radio/together/rss.xml");
			rssItem20.setPubDate(new Date()); 
			
			TableRss rssItem21 = new TableRss();
			rssItem21.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem21.setCategory("The Song Tree (BBC Learning)");
			rssItem21.setDescription("The Song Tree (BBC Learning)"); 
			rssItem21.setLink("http://downloads.bbc.co.uk/podcasts/radio/songtree/rss.xml");
			rssItem21.setPubDate(new Date()); 
			
			TableRss rssItem22 = new TableRss();
			rssItem22.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem22.setCategory("Aesop's Fables (BBC Learning)");
			rssItem22.setDescription("Aesop's Fables (BBC Learning)"); 
			rssItem22.setLink("http://downloads.bbc.co.uk/podcasts/radio/aesop/rss.xml");
			rssItem22.setPubDate(new Date()); 
			
			TableRss rssItem23 = new TableRss();
			rssItem23.setWebsite(String.valueOf(EnumWebsite.BBC));
			rssItem23.setCategory("A Christmas Carol (BBC Learning)");
			rssItem23.setDescription("A Christmas Carol (BBC Learning)"); 
			rssItem23.setLink("http://downloads.bbc.co.uk/podcasts/radio/xmascarol/rss.xml");
			rssItem23.setPubDate(new Date()); 
			
			TableRss rssItem24 = new TableRss();
			rssItem24.setWebsite(String.valueOf(EnumWebsite.VOA));
			rssItem24.setCategory("Learning English - Words and Their Stories");
			rssItem24.setDescription("Learning English - Words and Their Stories"); 
			rssItem24.setLink("http://feed.theplatform.com/f/KI6AEB/TAx6FSvAJOmT");
			rssItem24.setPubDate(new Date()); 
			
			TableRss rssItem25 = new TableRss();
			rssItem25.setWebsite(String.valueOf(EnumWebsite.VOA));
			rssItem25.setCategory("Learning English - Health Report");
			rssItem25.setDescription("Learning English - Health Report"); 
			rssItem25.setLink("http://feed.voanews.com/f/KI6AEB/ByeMvAAau5cg");
			rssItem25.setPubDate(new Date()); 
			
			TableRss rssItem26 = new TableRss();
			rssItem26.setWebsite(String.valueOf(EnumWebsite.VOA));
			rssItem26.setCategory("VOA: Special English TV");
			rssItem26.setDescription("VOA: Special English TV"); 
			rssItem26.setLink("http://feeds.voanews.com/ps/getRSS?client=Standard&PID=Kgg8fGY4kMiiLgNvDIpYDBGSPOo9mmBg&startIndex=1&endIndex=500");
			rssItem26.setPubDate(new Date()); 
			
			
			
			schemaHelper.addTableRss(rssItem1);
			schemaHelper.addTableRss(rssItem2);
			schemaHelper.addTableRss(rssItem3);
			schemaHelper.addTableRss(rssItem4);
			schemaHelper.addTableRss(rssItem5);
			schemaHelper.addTableRss(rssItem6);
			schemaHelper.addTableRss(rssItem7);
			schemaHelper.addTableRss(rssItem8);
			schemaHelper.addTableRss(rssItem9);
			schemaHelper.addTableRss(rssItem10);
			schemaHelper.addTableRss(rssItem11);
			schemaHelper.addTableRss(rssItem12);
			schemaHelper.addTableRss(rssItem13);
			schemaHelper.addTableRss(rssItem14);
			schemaHelper.addTableRss(rssItem15);
			schemaHelper.addTableRss(rssItem16);
			schemaHelper.addTableRss(rssItem17);
			schemaHelper.addTableRss(rssItem18);
			schemaHelper.addTableRss(rssItem19);
			schemaHelper.addTableRss(rssItem20);
			schemaHelper.addTableRss(rssItem21);
			schemaHelper.addTableRss(rssItem22);
			schemaHelper.addTableRss(rssItem23);
			schemaHelper.addTableRss(rssItem24);
			schemaHelper.addTableRss(rssItem25);
			schemaHelper.addTableRss(rssItem26);
		}
	}
	
}
